package com.example.controller.shop;


import com.example.common.Result;
import com.example.entity.shop.DamageReport;
import com.example.entity.shop.SellerProduct;
import com.example.service.shop.SellerProductService;
import com.example.service.utils.InventoryRecommendation;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 卖家出售的商品表前端操作接口
 **/
@RestController
@RequestMapping("/sellerProduct")
public class SellerProductController {

    @Resource
    private SellerProductService sellerProductService;
    @Resource
    private InventoryRecommendation inventoryRecommendation;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody SellerProduct sellerProduct) {
        sellerProductService.add(sellerProduct);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        sellerProductService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        sellerProductService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody SellerProduct sellerProduct) {
        sellerProductService.updateById(sellerProduct);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        SellerProduct sellerProduct = sellerProductService.selectById(id);
        return Result.success(sellerProduct);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(SellerProduct sellerProduct) {
        List<SellerProduct> list = sellerProductService.selectAll(sellerProduct);
        return Result.success(list);
    }

    /**
     * 批量查询
     * @param ids
     * @return
     */
    @PostMapping("/selectByIds")
    public Result selectByIds(@RequestBody List<Integer> ids){
        List<SellerProduct> list = sellerProductService.selectByIds(ids);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(SellerProduct sellerProduct,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<SellerProduct> page = sellerProductService.selectPage(sellerProduct, pageNum, pageSize);
        return Result.success(page);
    }

    /**
     * 查询所有商品类别distinct
     * @return
     */
    @GetMapping("/selectAllCategory")
    public Result selectAllCategory(){
        List<SellerProduct> categroyList = sellerProductService.selectAllCategory();
        return Result.success(categroyList);
    }

    /**
     * 查询库存不足商品
     * @param sellerProduct
     * @param pageNum
     * @param pageSize
     * @return
     */

    @GetMapping("/selectStockNotEnough")
    public Result selectStockNotEnough(SellerProduct sellerProduct,
                                       @RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<SellerProduct> page = sellerProductService.selectStockNotEnough(sellerProduct,pageNum,pageSize);
        return Result.success(page);

    }

    /**
     *  查询所有商品类别，以及类别数据，用于柱状图
     * @return
     */
    @GetMapping("/countCategory")
    public Result countCategory(){
        List<SellerProduct> categroyList = sellerProductService.selectCategoryCount();
        return Result.success(categroyList);
    }

    /**
     * 库存推荐
     * @param id
     * @return
     */
    @GetMapping("/inventoryRecommendation/{id}")
    public Result inventoryRecommand(@PathVariable Integer id) {
        int recommendedStock = inventoryRecommendation.inventoryQuantity(id);
        return Result.success(recommendedStock);
    }

    /**
     * 批量修改盘点数据
     * @param sellerProducts
     * @return
     */
    @PostMapping("/updateBatch")
    public Result updateBatch(@RequestBody List<SellerProduct> sellerProducts){
        sellerProductService.updateBatch(sellerProducts);
        return Result.success();
    }
}